package cc.jt.cc;

import java.util.concurrent.TimeUnit;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DataFetcher {

  public static long sleep100() {
    return sleepAndEcho(100);
  }

  public static long sleep200() {
    return sleepAndEcho(200);
  }

  public static long sleep300() {
    return sleepAndEcho(300);
  }

  public static long sleep400() {
    return sleepAndEcho(400);
  }

  public static long sleep500() {
    return sleepAndEcho(500);
  }

  public static long sleep600() {
    return sleepAndEcho(600);
  }

  public static long sleep1s() {
    return sleepAndEcho(1000);
  }

  @SneakyThrows
  public static long sleepAndEcho(long timeMill) {
    log.debug("sleep {} ms", timeMill);
    TimeUnit.MILLISECONDS.sleep(timeMill);
    return timeMill;
  }

  @SneakyThrows
  public static long sleepAndEcho(String index, long timeMill) {
//    log.debug("{} sleep {} ms", index, timeMill);
    TimeUnit.MILLISECONDS.sleep(timeMill);
    return timeMill;
  }

  @SneakyThrows
  public static long sleepAndThrow(String index, long timeMill) {
//    log.debug("{} sleep {} ms", index, timeMill);
    TimeUnit.MILLISECONDS.sleep(timeMill);
    if (timeMill > 100) {
      throw new RuntimeException("timeMill > 100");
    }
    return timeMill;
  }
}
